FacClient Methods
The FacClient object contains the following methods:
Some of the automation calls in this API support multithreading. If supported it is noted below. If multithreading is not noted, the call is single-threaded.
AddFacilityRecord
The AddFacilityRecord method adds a new facility from an XML record.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
AddFacilityRecord(RecordXML as String)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
RecordXML |
Yes |
The XML record that contains the attributes that will be stored in the new facility. |
Remarks
The XML used to create the facility should be in the same format as the XML returned from ReadFacilityRecord, as in the following example.
<CygNetFacilityRecord lock_user="VSI\" lock_time="-1214347123" facility_attr0="" facility_attr1="" facility_category="REMDEV" facility_desc="CYGDEMO_RTU" facility_id="Cyg_RTU" facility_info0="" facility_info1="" facility_is_active="Y" facility_is_ref_any="Y" ... />
Example
The following example creates a new facility using an XML record stored in edtXML.
AddFacilityRecord
Sub AddRecord()
FacClient.AddFacilityRecord edtXML.Text
MsgBox "Facility Added"
End Sub
Connect
The Connect method connects the object to a service.
Syntax
Connect(DomainSiteService As String)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
DomainSiteService |
Yes |
The [Domain]Site.Service to which to connect. The domain is optional. The service must be a valid one. |
Remarks
Returns 0 if successful and a non-zero value if the connection failed.
Example
The following example connects the Client object to the CYGDEMO.<SVC> on domain 5410:
Connect
Sub FacConnect()
'Connect to a FAC
Dim FacClient
Set FacClient = CreateObject("CxFac.FacClient")
FacClient.Connect("[5410]CYGDEMO.FAC")
End Sub
DeleteFacilityRecord
The DeleteFacilityRecord method deletes a facility.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
DeleteFacilityRecord(FacTag as String) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
FacTag |
Yes |
The facility to delete. |
Example
The following example deletes a facility and notifies the user if an error occurs.
DeleteFacilityRecord
Sub DeleteFacRecord()
Dim Success
Success = FacClient.DeleteFacilityRecord ("CYGDEMO.UIS::CYG_METER")
If Success = True Then
MsgBox "Facility deleted"
Else
MsgBox "Error in deleting"
End IF
End Sub
Disconnect
The Disconnect method disconnects from the connected service.
Syntax
Disconnect() As Integer
Remarks
The Disconnect method returns 0 if successful and a non-zero value if the disconnect failed.
Example
The following example disconnects the Client object from the connected service, and pops a message box if it is unsuccessful:
Sub Svc.Disconnect()
<SvcClient>.Disconnect()
MsgBox "Service has disconnected."
If <SvcClient>.Disconnect <> 0
Then
MsgBox "Failed to disconnect."
End If
End Sub
FacilityExists
The FacilityExists methods check to see if the named facility tag exists.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
FacilityExists(ByVal FacTag As String) As Boolean
Parameters
| Parameter | Required | Description |
|---|---|---|
|
FacTag |
Yes |
The tag of the facility for which to check. |
Remarks
This methods returns true if the specified facility exists.
FinishBulkUpdates
The FinishBulkUpdates method disables bulk updating.
Syntax
FinishBulkUpdates()
Remarks
This method disables bulk updating and makes the FAC flush changes to the disk after every point is updated.
Example
The following example stops bulk updating and restores normal updating.
FinishBulkUpdates
Sub StopBulkUpdates()
FacClient.FinishBulkUpdates
MsgBox "Bulk Updating disabled"
End Sub
GetActiveServices
The GetActiveServices method returns a list of active FAC services.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
GetActiveServices(ServiceList as Array)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
ServiceList |
Yes |
The list of IDs of active facilities returned by this method. |
Example
The following example retrieves a list of active FAC services and stores them in a list box.
GetActiveServices
Sub GetActiveServices()
Dim activeServices
Dim fac
FacClient.GetActiveServices activeServices
For Each fac In activeServices
lboFac.AddString(fac)
Next
End Sub
GetConsoleData
The GetConsoleData method returns the console text and display attributes as two 25x80 arrays of unsigned characters.
Syntax
GetConsoleData(ByRef pText, ByRef pAttr) As Integer
Parameters
| Parameter | Required | Description |
|---|---|---|
|
pText |
Yes |
A two-dimensional 25x80 array of console text attributes returned by this method. |
|
pAttr |
Yes |
A two-dimensional 25x80 array of console display attributes returned by this method. |
Remarks
This method returns 0 if successful.
Example
The following example writes the console text and display attributes to a CSV file.
Sub
Dim aryText, aryAttr, nRet
nRet = <NameofServiceClientObject>.GetConsoleData(aryText, aryAttr)
' Write text attributes to CSV file
Dim i, j, strMsg
For i = 0 To UBound(aryText, 1)
For j = 0 To UBound(aryText, 2)
strMsg = strMsg + CStr(aryText(i, j)) + ","
Next
strMsg = strMsg + vbCr
Next
dim fso, file
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("c:\console_text_attrs.csv", 2, True)
file.WriteLine(strMsg)
file.Close
strMsg = ""
' Write display attributes to CSV file
For i = 0 To UBound(aryAttr, 1)
For j = 0 To UBound(aryAttr, 2)
strMsg = strMsg + CStr(aryAttr(i, j)) + ","
Next
strMsg = strMsg + vbCr
Next
Set file = fso.OpenTextFile("c:\console_disp_attrs.csv", 2, True)
file.WriteLine(strMsg)
file.Close
MsgBox nRet
End Sub
GetCvsOnlyFacilities
The GetCvsOnlyFacilities method returns a list of current value service facilities.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
GetCvsOnlyFacilites(SiteService as String, FacilityList as Array)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
SiteService |
Yes |
The Site.Service to which the facilities are connected. This parameter must specify a current value service. |
|
FacilityList |
Yes |
The list of facilities returned by this method. |
Remarks
The returned list will not include facilities associated with the DDS, such as remote device or communication device facilities.
Example
The following example retrieves all facilities associated with CYGDEMO.UIS and displays them in a list box.
GetCvsOnlyFacilities
Sub GetCvsFacs()
Dim CvsList
Dim fac
FacClient.GetCvsOnlyFacilities "CYGDEMO.UIS", CvsList
For Each fac In CvsList
lboFac.AddString(fac)
Next
End Sub
GetCvsServiceList
The GetCvsServiceList method returns the service names of all current value services referenced by facility records.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
GetCvsServiceList(ServiceList as Array)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
ServiceList |
Yes |
The list of current value services returned by this method. |
Remarks
The returned service names will be in Site.Service format.
Example
The following example gets all the current value services that the facilities are associated with and stores them in a list box.
GetCvsServiceList
Sub GetCvsServices()
Dim CvsList
Dim cvs
'Get a list of CVSes associated with the PNT service
FacClient.GetCvsServiceList CvsList
'Store each CVS in a list box
For Each cvs In CvsList
lboCvs.AddString(cvs)
Next
End Sub
GetDeviceCatSpecificFacilities
The GetDeviceCatSpecificFacilities method returns the list of facilities with a specified device category type.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
GetDeviceCatSpecificFacilities(SiteService as String, DeviceCategory as String, FacilityList as Array)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
SiteService |
Yes |
The Site.Service with which the facilities are associated. This parameter must specify a current value service. |
|
DeviceCategory |
Yes |
The device category of the device. Valid device category options are:
|
|
FacilityList |
Yes |
The list of facilities returned by this method. |
Example
The following example retrieves all facilities with a device category of RD, and displays them in a list box.
GetDeviceCatSpecificFacilities
Sub GetDeviceCatFacs()
Dim FacList
Dim fac
FacClient.GetDeviceCatSpecificFacilities "CYGDEMO.UIS", "RD", FacList
For Each fac In FacList
lboFac.AddString(fac)
Next
End Sub
GetEmptyRecordXml
The GetEmptyRecordXml method returns an empty facility record XML.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
GetEmptyRecordXml() As String
Remarks
This method can be used in the process of creating a new facility. After the empty record XML is retrieved, use the SetRecordXMLAttribute method to set the new facilty record attribute values. Then use the AddFacilityRecord method to add the new facility from the XML string created by the SetRecordXMLAttribute method.
The string is returned as XML. The following is an example of what this method will return.
Example
The following example gets the XML for an empty facility and saves it to an XML document.
GetEmptyRecordXml
Sub GetEmptyRecord()
'Get facility xml
Dim strInfo
strInfo = FacClient.GetEmptyRecordXml
'Save XML
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.loadXML(strInfo)
xmlDoc.save("C:\EmptyFacility.xml")
End Sub
GetFacilitiesByFacilityType
The GetFacilitiesByFacilityType method returns the list of facilities of a specified facility type.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
GetFacilitiesByFacilityType(FacilityType as String, SiteService as String, FacilityList as Array)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
FacilityType |
Yes |
The facility type of the facilities to be retrieved. |
|
SiteService |
Yes |
The Site.Service of the current value service with which the facilities are associated. |
|
FacilityList |
Yes |
The list of facilities returned by this method. |
Example
The following example retrieves all facilities with a facility type of "REMDEV" and displays them in a list box.
GetFacilitiesByFacilityType
Sub GetByFacilityType()
Dim FacList
Dim fac
FacClient.GetFacilitiesByFacilityType "REMDEV", "CYGDEMO.UIS", FacList
For Each fac In FacList
lboFac.AddString(fac)
Next
End Sub
GetFacilitiesList
The GetFacilitiesList method returns the list of the facilities associated with a given Site.Service.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
GetFacilitiesList(SiteService as String, FacilityList as Array)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
SiteService |
Yes |
The Site.Service of the current value service with which the facilities are associated. |
|
FacilityList |
Yes |
The list of facilities returned by this method. |
Remarks
The returned list of facilities will be stored and sorted in alphabetical order by facility tag.
Example
The following example retrieves all facilities associated with CYGDEMO.UIS and displays them in a list box.
GetFacilitiesList
Sub GetFacilitiesList()
Dim FacList
Dim facility
FacClient.GetFacilitiesList "CYGDEMO.UIS", FacList
For Each facility In FacList
lboFac.AddString(fac)
Next
End Sub
GetFacilityAttributeList
The GetFacilityAttributeList method returns the list of attribute names that can be stored in a facility.
Syntax
GetFacilityAttributeList(FacilityList as Array)
Parameters
| Parameter | Required | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
FacilityList |
Yes |
Output. The returned two-dimensional array of service definitions. The array order is defined as follows:
|
Example
The following example retrieves a list of attribute names and displays them in a list box.
GetFacilityAttributeList
Sub GetFacAttributes()
Dim arrFacAttrs
FacClient.GetFacilityAttributeList arrFacAttrs
Dim strFacAttr
Dim iStep
For iStep = 0 To UBound(arrFacAttrs)
strFacAttr = arrFacAttrs(iStep, 0) & ", " & 'attribute number
arrFacAttrs(iStep, 1) & ", " & 'attribute short name
arrFacAttrs(iStep, 2) & ", " & 'attribute description
arrFacAttrs(iStep, 3) & ", " & 'attribute category
arrFacAttrs(iStep, 4) 'attribute in use (True/False)
lboFac.AddString(strFacAttr)
Next
End Sub
GetFacilityTagList
The GetFacilityTagList retrieves a list of facility tags. The criteria can use the simplified 'key1=value1;key2=value2' form or the XML rules form.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
GetFacilityTagList(ByVal bstrFilter As String, ByRef pvFacilityTagList)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
Filter |
Yes |
The filter to limit the list of tags returned. |
|
FacilityTagList |
Yes |
The list of facility tags returned by this method. |
Remarks
Returns a list of facility tags for the specified criteria.
GetFacilityTypeList
The GetFacilityTypeList method returns the list of facility types for the given FAC service.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
GetFacilityTypeList(SiteService as String, FacilityTypeList As Variant)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
SiteService |
Yes |
The Site.Service for which to retrieve a list of facility types. If this parameter is an empty string, all facility types will be returned. |
|
FacilityTypeList |
Yes |
The list of facility types returned by this method. |
Example
The following example displays the list of all facility types.
GetFacilityTypeList
Sub
Dim aryFacTypes
FacClient.GetFacilityTypeList "", aryFacTypes
Dim i, strMsg
For i = 0 To UBound(aryFacTypes)
strMsg = strMsg + aryFacTypes(i) + vbCr
Next
MsgBox strMsg
End Sub
GetRecordXMLAttribute
The GetRecordXMLAttribute method returns the value of an attribute from a facility record.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
GetRecordXMLAttribute(RecordXML as String, RecordAttribute as String) As String
Parameters
| Parameter | Required | Description |
|---|---|---|
|
RecordXML |
Yes |
The XML record from which to retrieve the attribute value. |
|
RecordAttribute |
Yes |
The name of the attribute for which to retrieve a value. If this attribute is not present in RecordXML, this method will return an empty string. |
Example
The following example gets the value for the attribute facility_id and displays it in a message box.
GetRecordXMLAttribute
Sub GetRecordAttribute()
edtMessageBox.Test = FacClient.GetRecordXMLAttribute(edtXML.Text, "facility_id")
End Sub
GetReferences
The GetReferences method refreshes the list of services referenced by the connected service.
Syntax
GetReferences() As Integer
Return Values
This method returns all references for the connected service.
Example
The following example refreshes the connected services:
Sub GetReferences()
<NameofServiceClientObject>.GetReferences
MsgBox "Services references retrieved"
End Sub
Note: This method supports multithreading or the concurrent execution of multiple threads.
ReadFacilityRecord
The ReadFacilityRecord method returns the XML record for a facility.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
ReadFacilityRecord(FacTag as String) As String
Parameters
| Parameter | Required | Description |
|---|---|---|
|
FacTag |
Yes |
The tag of the facility for which to retrieve a record. |
Remarks
The record will be returned in XML format. The following is an example of an excerpt of the returned XML.
<CygNetFacilityRecord lock_user="VSI\" lock_time="-1214347123" facility_attr0="" facility_attr1="" facility_category="REMDEV" facility_desc="CYGDEMO_RTU" facility_id="Cyg_RTU" facility_info0="" facility_info1="" facility_is_active="Y" facility_is_ref_any="Y" ... />
Example
The following example retrieves a facility record and saves it to an XML file.
ReadFacilityRecord
Sub ReadFacRecord()
'Get facility xml
Dim Record
Record = FacClient.ReadFacilityRecord("CYGDEMO.UIS::Cyg_RTU")
'Save XML
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.loadXML(Record)
xmlDoc.save("C:\FacilityRecord.xml")
End Sub
ReadFacilityRecordForUpdate
The ReadFacilityRecordForUpdate method returns a facility record and locks the facility for updates.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
ReadFacilityRecordForUpdate(FacTag as String) As String
Parameters
| Parameter | Required | Description |
|---|---|---|
|
FacTag |
Yes |
The tag of the facility to read for updates. |
Remarks
The ReadFacilityRecordForUpdate method returns a record for the given facility and locks the record for update. When the record is locked for update, other users are prevented from editing it until the lock is released or times out. Follow this method by a call to UpdateFacilityRecord or ReleaseFacilityRecordLock.
Example
The following example displays a facility record in edtXML and locks the facility for updates.
ReadFacilityRecordForUpdate
Sub ReadFacRecordForUpdate()
edtXML.Text = FacClient.ReadFacilityRecordForUpdate(Tag)
MsgBox "Facility locked"
End Sub
ReadFacilityRecords
The ReadFacilityRecords method returns an XML string containing records for each of the given facility tags.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
ReadFacilityRecords(ArrFacTags as Variant) As String
Parameters
| Parameter | Required | Description |
|---|---|---|
|
ArrFacTags |
Yes |
A list of facility tags for which to retrieve records. |
Remarks
The records will be returned in XML format. The following is an example of an excerpt of the returned XML.
<CygNetFacilityRecords>
<CygNetFacilityRecord lock_user="FAC" lock_time="-1298593501" facility_attr0="" facility_attr1="" facility_attr10="" facility_attr11="" facility_attr12="" facility_attr13="" facility_attr14="" facility_attr15="" facility_attr16="" facility_attr17="" .../>
...
</CygNetFacilityRecords>
Example
The following example writes facility records to an XML file.
ReadFacilityRecords
Sub
Dim aryFacTags
ReDim aryFacTags(2)
aryFacTags(0) = "CYGDEMO.UIS::20230303"
aryFacTags(1) = "CYGDEMO.UIS::FLOWAUTOAP15"
aryFacTags(2) = "CYGDEMO.UIS::FLOWAUTOAP15A"
Dim strXml
strXml = FacClient.ReadFacilityRecords(aryFacTags)
'Save XML
Dim xmlDoc
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.loadXML(strXml)
xmlDoc.save("C:\FacilityRecords.xml")
End Sub
ReleaseFacilityRecordLock
The ReleaseFacilityRecordLock method unlocks a facility record to allow editing.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
ReleaseFacilityRecordLock(FacTag as String, RecordXML as String)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
FacTag |
Yes |
The tag of the facility to unlock. Use the format SITE.SERVICE::FACILITYID |
|
RecordXML |
Yes |
The XML record of the facility to unlock. Generated by ReadFacilityRecord. |
Remarks
This method releases the lock on the facility record created by the ReadFacilityRecordForUpdate method. Once the lock on the record is released, it can then be edited by other users.
Example
The following example unlocks the CYGDEMO_RTU facility record.
ReleaseFacilityRecordLock
Sub ReleaseFacLock()
FacClient.ReleaseFacilityRecordLock Tag, XML
MsgBox "Facility unlocked"
End Sub
SetRecordXMLAttribute
The SetRecordXMLAttribute method sets an attribute value of a specified facility record.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
SetRecordXMLAttribute(RecordXML as String, RecordAttribute as String, AttributeValue as String) As String
Parameters
| Parameter | Required | Description |
|---|---|---|
|
RecordXML |
Yes |
The facility record XML for which to set an attribute. Generated by ReadFacilityRecord. |
|
RecordAttribute |
Yes |
The attribute for which to set a value. |
|
AttributeValue |
Yes |
The new value of the attribute. |
Remarks
This method creates a new XML string containing updated facility attribute values to be used by either the UpdateFacilityRecords method for a single facility record or the UpdateAttributesForFacilities method for updating multiple facility records.
SetRecordXmlAttribute sets the attribute name to lowercase before modifying the XML.
Example
The following example creates a new XML string with the new facility record attribute value, but doesn’t update the facility itself.
SetRecordXMLAttribute
Sub SetRecordAtt()
Dim newPoint
newPoint = FacClient.SetRecordXMLAttribute (XML, "facility_category" "REMDEV")
edtMessageBox.Text = newPoint
End Sub
StartBulkUpdates
The StartBulkUpdates method enables faster updating.
Syntax
StartBulkUpdates()
Remarks
Normally, the FAC service will flush the changes to the disk after each facility is updated. If Bulk Updating is enabled, it will only flush every thirty seconds. This decreases the update time but increases the likelihood that data will be lost if a bad shutdown occurs. CygNet recommends that this feature only be turned on while bulk updating occurs and then turned off when finished, using FinishBulkUpdates.
Example
The following example enables Bulk Updating.
StartBulkUpdates
Sub StartBulkUpdates()
FacClient.StartBulkUpdates()
MsgBox "FAC Client has started bulk updating"
End Sub
UpdateAttributesForFacilities
The UpdateAttributesForFacilities method updates multiple facility records with new attribute values from an XML string.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
UpdateAttributeForFacilities(FacTags as Array, RecordXML as String, errors as Array) As Integer
Parameters
| Parameter | Required | Description |
|---|---|---|
|
FacTags |
Yes |
The array of tags of facilities to be updated |
|
RecordXML |
Yes |
The XML string that contains the new facility attribute values. |
|
errors |
Yes |
A list of errors returned by this method. |
Remarks
This method updates multiple facility records using the XML string returned by the SetRecordXMLAttribute method.
For the RecordXML used in this method, do not include an entire facility record since the method updates multiple facility records. The update would fail as a result of trying to create multiple instances of an identical facility record. The XML string should only contain the attributes that you want to be set the same on all the facilities that are to be updated. The attributes that are not included in the XML string will not be updated when the method is called.
For example, if the following is stored in RecordXML, only Facility Attribute 0 will be updated:
Example
The following example updates an array of facilities with the attributes from edtXML, and outputs a list of errors in lboerrors.
UpdateAttributesForFacilities
Sub UpdateAttributes()
Dim Tags(1)
Dim errors(1)
Dim err
Tags(0) = "CYGDEMO.UIS::CYG_RTU"
Tags(1) = "CYGDEMO.UIS::CYG_METER"
FacClient.UpdateAttributesForFacilities Tags, edtXML.Text, errors
For Each err In errors
lboerrors.AddString(err)
Next
MsgBox "Facilities updated"
End Sub
UpdateFacilityRecord
The UpdateFacilityRecord method updates a single facility record from an XML string.
Note: This method supports multithreading or the concurrent execution of multiple threads.
Syntax
UpdateFacilityRecord(FacTag as String, RecordXML as String)
Parameters
| Parameter | Required | Description |
|---|---|---|
|
FacTag |
Yes |
The tag of the facility to update. |
|
RecordXML |
Yes |
The XML string containing the new facility attribute values. |
Remarks
This method updates a single facility record using the XML string returned by the SetRecordXMLAttribute method.
RecordXML does not need to contain an entire facility record. If an attribute is left out, it will not be updated when this method is called. For example, if the following is stored in RecordXML, only Facility Attribute 0 will be updated:
Example
The following example updates a facility record with the modified XML stored in edtXML.
UpdateFacilityRecord
Sub UpdateFacRecord()
FacClient.UpdateFacilityRecord Tag, edtXML.Text
MsgBox "Facility Updated"
End Sub


